package com.kevin.j2eeToolBox.serializable;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;

public class SerializableTest1 {

	/**
	 * @param args
	 * @throws IOException
	 * @throws ClassNotFoundException
	 */
	public static void main(String[] args) throws IOException,
			ClassNotFoundException {

		Person person = new Person(20, "kevin", true);

		OutputStream os = new FileOutputStream("temp.txt");
		ObjectOutputStream oos = new ObjectOutputStream(os);

		oos.writeObject(person);

		oos.close();

		InputStream is = new FileInputStream("temp.txt");
		ObjectInputStream ois = new ObjectInputStream(is);

		Object p = ois.readObject();

		// while (null != (p = ois.readObject())) {
		System.out.println(((Person) p).getName() + "  "
				+ ((Person) p).getAge() + "  " + ((Person) p).isStudent());
		// }

		ois.close();

	}
}

class Person implements Serializable {

	private int age;
	private transient String name;
	private boolean isStudent;

	public Person(int age, String name, boolean isStudent) {
		super();
		this.age = age;
		this.name = name;
		this.isStudent = isStudent;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isStudent() {
		return isStudent;
	}

	public void setStudent(boolean isStudent) {
		this.isStudent = isStudent;
	}

}
